package md.mru.transfer;

import md.mru.backend.common.BaseDtoMapper;
import md.mru.transfer.old.domain.*;
import md.mru.transfer.old.repository.*;
import md.mru.transfer.optimized.domain.*;
import md.mru.transfer.optimized.repository.*;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * @author sergiu.marin
 * @since 01.05.2014.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/config/transfer-application-config.xml"})
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TransferService {

    @Autowired
    private CtzTransferRepository ctzTransferRepository;
    @Autowired
    private CtzTpeTransferRepository ctzTpeTransferRepository;
    @Autowired
    private AgrTransferRepository agrTransferRepository;
    @Autowired
    private CntTransferRepository cntTransferRepository;
    @Autowired
    private DcmTransferRepository dcmTransferRepository;
    @Autowired
    private DosarTransferRepository dosarTransferRepository;
    @Autowired
    private FmlRltTransferRepository fmlRltTransferRepository;
    @Autowired
    private FmlStsTransferRepository fmlStsTransferRepository;
    @Autowired
    private FmlTransferRepository fmlTransferRepository;
    @Autowired
    private LngKnwTransferRepository lngKnwTransferRepository;
    @Autowired
    private LngTpeTransferRepository lngTpeTransferRepository;
    @Autowired
    private LngTransferRepository lngTransferRepository;
    @Autowired
    private LnkTreDsrTransferRepository lnkTreDsrTransferRepository;
    @Autowired
    private NmlDcmTransferRepository nmlDcmTransferRepository;
    @Autowired
    private NmlFncTransferRepository nmlFncTransferRepository;
    @Autowired
    private NmlFpTransferRepository nmlFpTransferRepository;
    @Autowired
    private NmlSteTransferRepository nmlSteTransferRepository;
    @Autowired
    private NtlTransferRepository ntlTransferRepository;
    @Autowired
    private SalGrdTransferRepository salGrdTransferRepository;
    @Autowired
    private SalTransferRepository salTransferRepository;
    @Autowired
    private SalTrpTransferRepository salTrpTransferRepository;
    @Autowired
    private SexTransferRepository sexOldTransferRepository;
    @Autowired
    private StdCtgTransferRepository stdCtgTransferRepository;
    @Autowired
    private StdSpcTransferRepository stdSpcTransferRepository;
    @Autowired
    private StdStdTransferRepository stdStdTransferRepository;
    @Autowired
    private StdTransferRepository stdTransferRepository;
    @Autowired
    private TreeGroupLinkTransferRepository treeGroupLinkTransferRepository;
    @Autowired
    private TreTransferRepository treTransferRepository;
    @Autowired
    private TypeTpeTransferRepository typeTpeTransferRepository;
    @Autowired
    private UserTransferRepository userTransferRepository;
    @Autowired
    private UsrGrpLnkTransferRepository usrGrpLnkTransferRepository;
    @Autowired
    private GrpTransferRepository grpTransferRepository;
    @Autowired
    private WrkTabTransferRepository wrkTabTransferRepository;
    @Autowired
    private WrkTpeTransferRepository wrkTpeTransferRepository;


    @Autowired
    private CitizenTransferRepository citizenTransferRepository;
    @Autowired
    private CitizenshipTransferRepository citizenshipTransferRepository;
    @Autowired
    private ContractTransferRepository contractTransferRepository;
    @Autowired
    private ContractAgreementTransferRepository contractAgreementTransferRepository;
    @Autowired
    private DocumentTransferRepository documentTransferRepository;
    @Autowired
    private DocumentTypeTransferRepository documentTypeTransferRepository;
    @Autowired
    private EducationTransferRepository educationTransferRepository;
    @Autowired
    private EducationCategoryTransferRepository educationCategoryTransferRepository;
    @Autowired
    private EducationSpecialityTransferRepository educationSpecialityTransferRepository;
    @Autowired
    private EducationStudyTransferRepository educationStudyTransferRepository;
    @Autowired
    private FamilyMemberTransferRepository familyMemberTransferRepository;
    @Autowired
    private FamilyRelationTransferRepository familyRelationTransferRepository;
    @Autowired
    private FamilyStatusTransferRepository familyStatusTransferRepository;
    @Autowired
    private FolderStateTransferRepository folderStateTransferRepository;
    @Autowired
    private FolderTransferRepository folderTransferRepository;
    @Autowired
    private FunctionClassificationTransferRepository functionClassificationTransferRepository;
    @Autowired
    private GroupClassificationTransferRepository groupClassificationTransferRepository;
    @Autowired
    private KnowledgeLevelTransferRepository knowledgeLevelTransferRepository;
    @Autowired
    private LanguageTransferRepository languageTransferRepository;
    @Autowired
    private ModernLanguageTransferRepository modernLanguageTransferRepository;
    @Autowired
    private NationalityTransferRepository nationalityTransferRepository;
    @Autowired
    private SalaryLevelTransferRepository salaryLevelTransferRepository;
    @Autowired
    private SalaryStepTransferRepository salaryStepTransferRepository;
    @Autowired
    private SalaryTransferRepository salaryTransferRepository;
    @Autowired
    private SexOptimizedTransferRepository sexOprimizedTransferRepository;
    @Autowired
    private TreeGroupLinkOptimizedTransferRepository treeGroupLinkOptimizedTransferRepository;
    @Autowired
    private TreeModelFolderTransferRepository treeModelFolderTransferRepository;
    @Autowired
    private TreeNodeModelTransferRepository treeNodeModelTransferRepository;
    @Autowired
    private TreeNodeTypeTransferRepository treeNodeTypeTransferRepository;
    @Autowired
    private UserGroupLinkTransferRepository userGroupLinkTransferRepository;
    @Autowired
    private UserOptimizedTransferRepository userOptimizedTransferRepository;
    @Autowired
    private UserGroupTransferRepository userGroupTransferRepository;
    @Autowired
    private WorkCategoryTransferRepository workCategoryTransferRepository;
    @Autowired
    private WorkExperienceTransferRepository workExperienceTransferRepository;

    @Autowired
    @Qualifier(value = "dtoMapper")
    private BaseDtoMapper mapper;

    @Test
    public void transfer01FolderStateData() {
        List<NmlSte> nmlStes = nmlSteTransferRepository.findAll();
        List<FolderState> folderStates = mapper.mapList(nmlStes, FolderState.class);
        folderStateTransferRepository.save(folderStates);
    }

    @Test
    public void transfer02FolderData() {
        List<Dosar> dosars = dosarTransferRepository.findAll();
        List<Folder> folders = mapper.mapList(dosars, Folder.class);
        folderTransferRepository.save(folders);
    }

    @Test
    public void transfer03CitizenTypeData() {
        List<CtzTpe> ctzTpes = ctzTpeTransferRepository.findAll();
        List<Citizenship> citizenships = mapper.mapList(ctzTpes, Citizenship.class);
        citizenshipTransferRepository.save(citizenships);
    }

    @Test
    public void transfer04CitizenData() {
        List<Ctz> ctzs = ctzTransferRepository.findAll();
        List<Citizen> citizens = mapper.mapList(ctzs, Citizen.class);
        citizenTransferRepository.save(citizens);
    }

    @Test
    public void transfer05ContractData() {
        List<Cnt> cnts = cntTransferRepository.findAll();
        List<Contract> contracts = mapper.mapList(cnts, Contract.class);
        contractTransferRepository.save(contracts);
    }

    @Test
    public void transfer06ContractAgreementData() {
        List<Agr> agrs = agrTransferRepository.findAll();
        List<ContractAgreement> contractAgreements = mapper.mapList(agrs, ContractAgreement.class);
        contractAgreementTransferRepository.save(contractAgreements);
    }

    @Test
    public void transfer07DocumentTypeData() {
        List<NmlDcm> nmlDcms = nmlDcmTransferRepository.findAll();
        List<DocumentType> documentTypes = mapper.mapList(nmlDcms, DocumentType.class);
        documentTypeTransferRepository.save(documentTypes);
    }

    @Test
    public void transfer08DocumentData() {
        List<Dcm> dcms = dcmTransferRepository.findAll();
        List<Document> documents = mapper.mapList(dcms, Document.class);
        documentTransferRepository.save(documents);
    }

    @Test
    public void transfer09EducationCategoryData() {
        List<StdCtg> stdCtgs = stdCtgTransferRepository.findAll();
        List<EducationCategory> educationCategories = mapper.mapList(stdCtgs, EducationCategory.class);
        educationCategoryTransferRepository.save(educationCategories);
    }

    @Test
    public void transfer10EducationSpecialityData() {
        List<StdSpc> stdSpcs = stdSpcTransferRepository.findAll();
        List<EducationSpeciality> educationSpecialities = mapper.mapList(stdSpcs, EducationSpeciality.class);
        educationSpecialityTransferRepository.save(educationSpecialities);
    }

    @Test
    public void transfer11EducationStudyData() {
        List<StdStd> stdStds = stdStdTransferRepository.findAll();
        List<EducationStudy> educationStudies = mapper.mapList(stdStds, EducationStudy.class);
        educationStudyTransferRepository.save(educationStudies);
    }

    @Test
    public void transfer12EducationData() {
        List<Std> stds = stdTransferRepository.findAll();
        List<Education> educations = mapper.mapList(stds, Education.class);
        educationTransferRepository.save(educations);
    }

    @Test
    public void transfer14FamilyRelationData() {
        List<FmlRlt> fmlRlts = fmlRltTransferRepository.findAll();
        List<FamilyRelation> familyRelations = mapper.mapList(fmlRlts, FamilyRelation.class);
        familyRelationTransferRepository.save(familyRelations);
    }

    @Test
    public void transfer15FamilyMemberData() {
        List<Fml> fmls = fmlTransferRepository.findAll();
        List<FamilyMember> familyMembers = mapper.mapList(fmls, FamilyMember.class);
        familyMemberTransferRepository.save(familyMembers);
    }

    @Test
    public void transfer16FamilyStatusData() {
        List<FmlSts> fmlStses = fmlStsTransferRepository.findAll();
        List<FamilyStatus> familyStatuses = mapper.mapList(fmlStses, FamilyStatus.class);
        familyStatusTransferRepository.save(familyStatuses);
    }

    @Test
    public void transfer17GroupClassificationData() {
        List<NmlFp> nmlFps = nmlFpTransferRepository.findAll();
        List<GroupClassification> groupClassifications = mapper.mapList(nmlFps, GroupClassification.class);
        groupClassificationTransferRepository.save(groupClassifications);
    }

    @Test
    public void transfer18FunctionClassificationData() {
        List<NmlFnc> nmlFncs = nmlFncTransferRepository.findAll();
        List<FunctionClassification> functionClassifications = mapper.mapList(nmlFncs, FunctionClassification.class);
        functionClassificationTransferRepository.save(functionClassifications);
    }

    @Test
    public void transfer19KnowledgeLevelData() {
        List<LngKnw> lngKnws = lngKnwTransferRepository.findAll();
        List<KnowledgeLevel> knowledgeLevels = mapper.mapList(lngKnws, KnowledgeLevel.class);
        knowledgeLevelTransferRepository.save(knowledgeLevels);
    }

    @Test
    public void transfer20ModernLanguageData() {
        List<LngTpe> lngTpes = lngTpeTransferRepository.findAll();
        List<Language> languages = mapper.mapList(lngTpes, Language.class);
        languageTransferRepository.save(languages);
    }

    @Test
    public void transfer21LanguageData() {
        List<Lng> lngs = lngTransferRepository.findAll();
        List<ModernLanguage> languages = mapper.mapList(lngs, ModernLanguage.class);
        modernLanguageTransferRepository.save(languages);
    }

    @Test
    public void transfer22NationalityData() {
        List<Ntl> ntls = ntlTransferRepository.findAll();
        List<Nationality> nationalities = mapper.mapList(ntls, Nationality.class);
        nationalityTransferRepository.save(nationalities);
    }

    @Test
    public void transfer23SalaryLevelData() {
        List<SalGrd> salGrds = salGrdTransferRepository.findAll();
        List<SalaryLevel> salaryLevels = mapper.mapList(salGrds, SalaryLevel.class);
        salaryLevelTransferRepository.save(salaryLevels);
    }

    @Test
    public void transfer24SalaryStepData() {
        List<SalTrp> salTrps = salTrpTransferRepository.findAll();
        List<SalaryStep> salarySteps = mapper.mapList(salTrps, SalaryStep.class);
        salaryStepTransferRepository.save(salarySteps);
    }

    @Test
    public void transfer25SalaryData() {
        List<Sal> sals = salTransferRepository.findAll();
        List<Salary> salaries = mapper.mapList(sals, Salary.class);
        salaryTransferRepository.save(salaries);
    }

    @Test
    public void transfer26SexData() {
        List<Sex> sexes = sexOldTransferRepository.findAll();
        List<SexOptimized> sexOptimizeds = mapper.mapList(sexes, SexOptimized.class);
        sexOprimizedTransferRepository.save(sexOptimizeds);
    }

    @Test
    public void transfer27UserGroupData() {
        List<Grp> grps = grpTransferRepository.findAll();
        List<UserGroup> userGroups = mapper.mapList(grps, UserGroup.class);
        userGroupTransferRepository.save(userGroups);
    }

    @Test
    public void transfer28TreeNodeModelData() {
        List<Tre> tres = treTransferRepository.findAll();
        List<TreeNodeModel> treeNodeModels = mapper.mapList(tres, TreeNodeModel.class);
        treeNodeModelTransferRepository.save(treeNodeModels);
    }

    @Test
    public void transfer29TreeNodeTypeData() {
        List<TypeTpe> typeTpes = typeTpeTransferRepository.findAll();
        List<TreeNodeType> treeNodeTypes = mapper.mapList(typeTpes, TreeNodeType.class);
        treeNodeTypeTransferRepository.save(treeNodeTypes);
    }

    @Test
    public void transfer30TreeGroupLinkData() {
        List<TreeGroupLink> treeGroupLinks = treeGroupLinkTransferRepository.findAll();
        List<TreeGroupLinkOptimized> treeGroupLinkOptimizeds = mapper.mapList(treeGroupLinks, TreeGroupLinkOptimized.class);
        treeGroupLinkOptimizedTransferRepository.save(treeGroupLinkOptimizeds);
    }

    @Test
    public void transfer31TreeModelFolderData() {
        List<LnkTreDsr> lnkTreDsrs = lnkTreDsrTransferRepository.findAll();
        List<TreeModelFolder> treeModelFolders = mapper.mapList(lnkTreDsrs, TreeModelFolder.class);
        treeModelFolderTransferRepository.save(treeModelFolders);
    }


    @Test
    public void transfer32UserData() {
        List<User> users = userTransferRepository.findAll();
        List<UserOptimized> userOptimizeds = mapper.mapList(users, UserOptimized.class);
        userOptimizedTransferRepository.save(userOptimizeds);
    }

    @Test
    public void transfer33UserGroupLinkData() {
        List<UsrGrpLnk> usrGrpLnks = usrGrpLnkTransferRepository.findAll();
        List<UserGroupLink> userGroupLinks = mapper.mapList(usrGrpLnks, UserGroupLink.class);
        userGroupLinkTransferRepository.save(userGroupLinks);
    }

    @Test
    public void transfer34WorkCategoryData() {
        List<WrkTpe> wrkTpes = wrkTpeTransferRepository.findAll();
        List<WorkCategory> workCategories = mapper.mapList(wrkTpes, WorkCategory.class);
        workCategoryTransferRepository.save(workCategories);
    }

    @Test
    public void transfer35WorkExperienceData() {
        List<WrkTab> wrkTabs = wrkTabTransferRepository.findAll();
        List<WorkExperience> workExperiences = mapper.mapList(wrkTabs, WorkExperience.class);
        workExperienceTransferRepository.save(workExperiences);
    }

}
